package com.yohann.eduorder.service.impl;

import com.yohann.commonutils.vo.CourseOrderVo;
import com.yohann.commonutils.vo.MemberOrderVo;
import com.yohann.eduorder.client.EduClient;
import com.yohann.eduorder.client.UcenterClient;
import com.yohann.eduorder.entity.Order;
import com.yohann.eduorder.mapper.OrderMapper;
import com.yohann.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yohann.eduorder.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author Yohann
 * @since 2020-08-28
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private EduClient eduClient;
    @Autowired
    private UcenterClient ucenterClient;

    /**
     * 创建订单
     * @param courseId
     * @param memberId
     * @return
     */
    @Override
    public String createOrder(String courseId, String memberId) {
        System.out.println(courseId+memberId);
        //远程调用获取用户信息
        MemberOrderVo memberInfo = ucenterClient.getMemberInfo(memberId);
        //远程调用获取课程信息
        CourseOrderVo courseOrderInfo = eduClient.getCourseOrderInfo(courseId);

        //创建订单
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseOrderInfo.getTitle());
        order.setCourseCover(courseOrderInfo.getCover());
        order.setTeacherName(courseOrderInfo.getTeacherName());
        order.setTotalFee(courseOrderInfo.getPrice());
        order.setMemberId(memberId);
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        order.setStatus(0);
        order.setPayType(1);

        baseMapper.insert(order);

        return order.getOrderNo();
    }
}
